package net.sx.minemodule.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseViewHolder;
import com.homegoods.classify.model.Constant;

import net.sx.minemodule.R;
import net.sx.minemodule.mvp.bean.SectionMultipleItem;

import java.util.List;

public class OrderDetailAdapter extends BaseSectionMultiItemQuickAdapter<SectionMultipleItem, BaseViewHolder> {

    private SectionMultipleItem  mData;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param sectionHeadResId The section head layout id for each item
     * @param data             A new list is created out of this one to avoid mutable list
     */
    public OrderDetailAdapter(int sectionHeadResId, List<SectionMultipleItem> data) {
        super(sectionHeadResId, data);
        addItemType(SectionMultipleItem.CONTENT, R.layout.mine_item_order_detail_content);
        addItemType(SectionMultipleItem.CONTENT_ADDITION, R.layout.mine_item_order_detail_content_addition);
        addItemType(SectionMultipleItem.CONTENT_RECEIVE, R.layout.mine_item_order_detail_content_received);
    }

    @Override
    protected void convertHead(BaseViewHolder helper, SectionMultipleItem item) {
        helper.setText(R.id.tv_name, item.orderListDetailBean.getStopName());
        Glide.with(mContext).load(Constant.SERVER_URL + item.orderListDetailBean.getShopImg()).into((ImageView) helper.getView(R.id.img_logo));
        mData = item;
    }


    @Override
    protected void convert(BaseViewHolder helper, SectionMultipleItem item) {
        switch (helper.getItemViewType()) {
            case SectionMultipleItem.CONTENT: //待付款、待发货、已发货 item布局
                Glide.with(mContext).load(item.getOrderProductsBean().getPic()).into((ImageView) helper.getView(R.id.img_commodity));

                String norms = ""; //规格
                for (int i = 0; i < item.getOrderProductsBean().getAttrs().size(); i++) {
                    norms = item.getOrderProductsBean().getAttrs().get(i).getName() + ":" + item.getOrderProductsBean().getAttrs().get(i).getValue() + "  ";
                }
                helper.setText(R.id.tv_name, item.getOrderProductsBean().getProductName())
                        .setText(R.id.tv_norms, norms)
                        .setText(R.id.tv_money, "¥" + item.getOrderProductsBean().getSalePrice())
                        .setText(R.id.tv_num, "x " + item.getOrderProductsBean().getNum());

                TextView tvFavorable = helper.getView(R.id.tv_favorable); //优惠tag //todo 未找到优惠字段
                TextView tvFreePost = helper.getView(R.id.tv_free_post); //包邮tag
                if (item.getOrderProductsBean().isDistributionType()) { //是否包邮
                    tvFreePost.setVisibility(View.VISIBLE);
                } else {
                    tvFreePost.setVisibility(View.GONE);
                }

                break;
            case SectionMultipleItem.CONTENT_ADDITION: //待付款 item附加布局
                //这里不是用的item数据而是header的数据
                helper.setText(R.id.tv_freight, "¥" + mData.orderListDetailBean.getOmsOrder().getFreightAmount()) //todo 单件运费字段未找到
                        .setText(R.id.tv_deduction, "¥" + "0")//todo 单件抵扣金额字段未找到
                        .setText(R.id.tv_num, "共" + mData.orderListDetailBean.getOrderProducts().size() + "件")
                        .setText(R.id.tv_payment_money, mData.orderListDetailBean.getOmsOrder().getTotalAmount())//
                        .addOnClickListener(R.id.tv_contact_service);
                break;
            case SectionMultipleItem.CONTENT_RECEIVE:  //已收货item布局
                //这里不是用的item数据而是header的数据
                Glide.with(mContext).load(item.getOrderProductsBean().getPic()).into((ImageView) helper.getView(R.id.img_commodity));

                String normsReceived = ""; //规格
                for (int i = 0; i < item.getOrderProductsBean().getAttrs().size(); i++) {
                    normsReceived = item.getOrderProductsBean().getAttrs().get(i).getName() + ":" + item.getOrderProductsBean().getAttrs().get(i).getValue() + "  ";
                }
                helper.setText(R.id.tv_name, item.getOrderProductsBean().getProductName())
                        .setText(R.id.tv_norms, normsReceived)
                        .setText(R.id.tv_money, "¥" + item.getOrderProductsBean().getSalePrice())
                        .setText(R.id.tv_num, "x " + item.getOrderProductsBean().getNum())
                        .addOnClickListener(R.id.tv_after_sale);

                TextView tvFavorableReceived = helper.getView(R.id.tv_favorable); //优惠tag //todo 未找到优惠字段
                TextView tvFreePostReceived = helper.getView(R.id.tv_free_post); //包邮tag
                if (item.getOrderProductsBean().isDistributionType()) { //是否包邮
                    tvFreePostReceived.setVisibility(View.VISIBLE);
                } else {
                    tvFreePostReceived.setVisibility(View.GONE);
                }
                break;
        }
    }


}
